home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6358 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.5 KB  |  98 lines

  1. Path: jupiter.planet.net!usenet
  2. From: cygnusx@planet.net (David)
  3. Newsgroups: comp.lang.c
  4. Subject: Help-Assignment2// This time I am posting the code!!!Thanx
  5. Date: Sat, 24 Feb 1996 03:58:34 GMT
  6. Organization: Planet Access Networks - Stanhope, NJ
  7. Message-ID: <312e8912.8777775@news.planet.net>
  8. NNTP-Posting-Host: newt19.planet.net
  9. X-Newsreader: Forte Agent .99d/32.182
  10.  
  11.  
  12. I got flamed pretty good for asking for help without posting any code
  13. on my last assignment so have included what I wrote on this one.
  14. anyway thanx to all of you who were kind enough to give me suggestions
  15. as I finished it and am on to a more challenging program ? well
  16. challenging for a green horn like me anyway !!!.
  17.  
  18. I wrote this program that prompts the user to input an amount of
  19. values the user  will enter . It then prompts for the specifed values
  20. and stores them . Then it calculates the High, low and average  of the
  21. inputed values in the array and prints them out. The problem is I
  22. would like to make these 3 calculations as Function Prototypes at the
  23. beginning of the program and have them called on  but am having
  24. trouble passing the array to them ???. 
  25.  
  26. The program below runs and does the specifed tasks but is not in
  27. function prototype form. Any Idea's on passing the array values to
  28. these functions????
  29.  
  30. Thanx much,  David
  31.  
  32. #include<stdio.h>
  33.  
  34. main()
  35. {
  36.  
  37. float A[100];
  38. float amount,total,value,max,ctr,min,avg;
  39.  
  40.  
  41. printf("  This Program accepts values from the user up to\n"
  42.        "  a maximum 100 and calculates the high, low and \n"
  43.        "  average of the total values entered.\n");
  44.  
  45. printf("\nPlease enter the amount of values you wish to use ?\n\n");
  46. scanf("%f",&amount);
  47.  
  48. for ( total =0;total<=amount-1;total++)
  49.  
  50.     { printf(" \nPlease enter a number : ");
  51.       scanf("%f",&A[total]);}
  52.                               
  53.  
  54. printf(" \n\nThe values you have entered are as follows\n\n");
  55.  
  56. for (value =0;value<=amount-1;value++)
  57.  
  58. printf("%6.1f",A[value]); 
  59.  
  60.  
  61. max=A[0];                                  /* max value calculation*/
  62.  
  63. for (ctr=1;ctr<amount;ctr++)
  64.  
  65.      if (A[ctr]>max)
  66.      {max=A[ctr];}
  67.      
  68. printf("\n\nThe Max Value of all entered is: %5.1f\n",max);
  69.  
  70.  
  71.  
  72. min=A[0];                                   /* min value calculation*/
  73.  
  74. for (ctr=1;ctr<amount;ctr++)
  75.  
  76.       if (A[ctr]<min)
  77.       {min=A[ctr];}
  78.  
  79. printf("\n\nThe Min Value of all entered is: %5.1f\n",min);
  80.  
  81.  
  82.  
  83. avg=A[0];                               /* average value calculation*/
  84.  
  85. for (ctr=1;ctr<amount;ctr++)
  86.  
  87.      avg += A[ctr];
  88.     
  89. printf("\n\nThe Avg Value of all entered is: %6.2f\n",avg/amount);
  90.  
  91. return 0; }
  92.  
  93.  
  94.  
  95.  
  96.     
  97.  
  98.